using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace VTGGoldMiner
{
    class PhaoNo
    {
        private DaoVang trochoi;
        private Texture2D[] anhphaono = new Texture2D[5];
        private Texture2D anhhienthi;
        private int toadox, toadoy, chieurong, chieudai;
        private float tiledanrong, tiledandai;
        private int chayphaono = 0, chaysolan = 0;
        public int anhien = 2;//1 la hien,2 la an
        public int baonophao = 0;
        private CacHam dungham;
        public PhaoNo(DaoVang trochoichinh, Texture2D[] anh, int ah, int tdx, int tdy, int rong, int dai, float tilerong, float tiledai)
        {
            trochoi = trochoichinh;
            dungham = new CacHam(trochoi.GraphicsDevice);
            anhphaono = anh;
            anhhienthi = anhphaono[0];
            anhien = ah;
            chieurong = rong; chieudai = dai;
            tiledanrong = tilerong; tiledandai = tiledai;
        }
        public void NapThongTinNo(int rong, int dai, int tdtamnox, int tdtamnoy)
        {
            chieurong = rong;
            chieudai = dai;
            toadox = tdtamnox - Convert.ToInt32(chieurong / 2);
            toadoy = tdtamnoy - Convert.ToInt32(chieudai / 2);
        }
        public void ChayNoPhao(int tocdo, int solan)
        {
            if (baonophao == 1)
            {
                if (anhien != 1) anhien = 1;
                if (chaysolan < solan)
                {
                    chayphaono++;
                    if (chayphaono == 1 * tocdo) anhhienthi = anhphaono[0];
                    else if (chayphaono == 2 * tocdo) anhhienthi = anhphaono[1];
                    else if (chayphaono == 3 * tocdo) anhhienthi = anhphaono[2];
                    else if (chayphaono == 4 * tocdo) anhhienthi = anhphaono[3];
                    else if (chayphaono == 5 * tocdo) { anhhienthi = anhphaono[4]; chayphaono = 0; chaysolan++; }
                }
                else LamMoiPhaoNo();
            }
        }
        public void LamMoiPhaoNo()
        {
            chayphaono = 0;
            chaysolan = 0;
            anhien = 2;
            baonophao = 0;
        }
        public void HienThi(SpriteBatch nenve)
        {
            if (anhien == 1) nenve.Draw(anhhienthi, dungham.BoHinhAnh(toadox, toadoy, chieurong, chieudai, tiledanrong, tiledandai), Color.White);
        }
    }
}